﻿using InstaMe.DB;
using InstaMe.Source.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InstaMe
{
    class MainProcess
    {
        private static MainProcess mInstance = null;
        private static object mLock = new object();
        private IDBListener mDBListener;

        public static MainProcess getInstance()
        {
            if (mInstance == null)
            {
                lock (mLock)
                {
                    if (mInstance == null)
                    {
                        mInstance = new MainProcess();
                    }
                }
            }
            return mInstance;
        }

        private MainProcess()
        {
            mDBListener = new IDBListener();
            mDBListener.setDBCompleteDelegate(new DBCompleteDelegate(OnDBRequestComplete));
        }

        public void PreLoadData()
        {
            //DBManager.getInstance().LoadDiaryItemAsync(mDBListener , 0);
        }

        private void OnDBRequestComplete(QueryObject aQueryObj)
        {
            byte iQueryAction = aQueryObj.getAction();
            if (iQueryAction == QueryObject.DB_LOAD_DIARY_ITEM)
            {
                List<DiaryItem> mListDiaryItem = (List<DiaryItem>)aQueryObj.getParam(QueryObject.KEY_LIST_DIARY_ITEM_RETURN);
                if (mListDiaryItem != null && mListDiaryItem.Count > 0)
                {
                    foreach (var item in mListDiaryItem)
                    {
                        //DiaryItemControl.getInstance().AddDiaryItemToMap(item);
                    }
                }
            }
        }

    }
}
